** This document generates variables and displays the commands for the OLS regressions in Table A.1 in the Appendix **

** Import MME Dataset to Generate Count Variables **
import excel FPA_Military_Statecraft_MMEs.xlsx, firstrow clear

* Generate Count Variables for Number of Shaping and Traditional Exercises *
by Ex_Year, sort: egen Ex_Type_Shaping_Count= count(Ex_Type) if Ex_Type=="Role-Forming/Building Partner Capacity" | Ex_Type=="Recruitment" | Ex_Type=="Trust Developing"
generate Ex_Type_Shaping= 1 if Ex_Type=="Role-Forming/Building Partner Capacity" | Ex_Type=="Recruitment" | Ex_Type=="Trust Developing"
replace Ex_Type_Shaping= 0 if Ex_Type=="Rehearsal" | Ex_Type=="Deterrence/Rehearsal"

generate Ex_China=1 if Country_A=="China" | Country_B=="China" | Country_C=="China" | Country_D=="China" | Country_E=="China" | Country_F=="China"| Country_G=="China"
generate Ex_Russia=1 if Country_A=="Soviet Union" | Country_A=="Russia" | Country_B=="Russia" | Country_C=="Russia" | Country_D=="Russia"| Country_E=="Russia"| Country_F=="Russia" | Country_G=="Russia"
generate Ex_USA=1 if Country_A=="USA" | Country_B=="USA" | Country_C=="USA" | Country_D=="USA" | Country_E=="USA"| Country_F=="USA"| Country_G=="USA"
generate Ex_India=1 if Country_A=="India" | Country_B=="India" | Country_C=="India" | Country_D=="India"| Country_E=="India"| Country_F=="India"| Country_G=="India"
generate Ex_Germany=1 if Country_A=="Germany" | Country_B=="Germany" | Country_C=="Germany" | Country_D=="Germany"| Country_E=="Germany" | Country_G=="Germany" | Country_F=="Germany" | Country_A=="West Germany" | Country_B=="West Germany" | Country_C=="West Germany" | Country_D=="West Germany"| Country_E=="West Germany"
generate Ex_France=1 if Country_A=="France" | Country_B=="France" | Country_C=="France" | Country_D=="France"| Country_E=="France" | Country_F=="France" | Country_G=="France"
generate Ex_UK=1 if Country_A=="UK" | Country_B=="UK" | Country_C=="UK" | Country_D=="UK"| Country_E=="UK" | Country_F=="UK" | Country_G=="UK"

by Ex_Year, sort: egen Ex_Count_Shaping_China= count(Ex_Type) if Ex_China==1 & Ex_Type_Shaping==1
by Ex_Year, sort: egen Ex_Count_Shaping_USA= count(Ex_Type) if Ex_USA==1 & Ex_Type_Shaping==1
by Ex_Year, sort: egen Ex_Count_Shaping_UK= count(Ex_Type) if Ex_UK==1 & Ex_Type_Shaping==1
by Ex_Year, sort: egen Ex_Count_Shaping_France= count(Ex_Type) if Ex_France==1 & Ex_Type_Shaping==1
by Ex_Year, sort: egen Ex_Count_Shaping_Germany= count(Ex_Type) if Ex_Germany==1 & Ex_Type_Shaping==1
by Ex_Year, sort: egen Ex_Count_Shaping_Russia= count(Ex_Type) if Ex_Russia==1 & Ex_Type_Shaping==1
by Ex_Year, sort: egen Ex_Count_Shaping_India= count(Ex_Type) if Ex_India==1 & Ex_Type_Shaping==1

by Ex_Year, sort: egen Ex_Count_Traditional_China= count(Ex_Type) if Ex_China==1 & Ex_Type_Shaping==0
by Ex_Year, sort: egen Ex_Count_Traditional_USA= count(Ex_Type) if Ex_USA==1 & Ex_Type_Shaping==0
by Ex_Year, sort: egen Ex_Count_Traditional_UK= count(Ex_Type) if Ex_UK==1 & Ex_Type_Shaping==0
by Ex_Year, sort: egen Ex_Count_Traditional_France= count(Ex_Type) if Ex_France==1 & Ex_Type_Shaping==0
by Ex_Year, sort: egen Ex_Count_Traditional_Germany= count(Ex_Type) if Ex_Germany==1 & Ex_Type_Shaping==0
by Ex_Year, sort: egen Ex_Count_Traditional_Russia= count(Ex_Type) if Ex_Russia==1 & Ex_Type_Shaping==0
by Ex_Year, sort: egen Ex_Count_Traditional_India= count(Ex_Type) if Ex_India==1 & Ex_Type_Shaping==0

* Tabulate Average Exercise Size by year to capture in dataset below *
by Ex_Year, sort: egen Ave_Troops_Year = mean(Approx_Ex_Size) 
by Ex_Year, sort: tab Ave_Troops_Year

* Tabulate Number of Shaping and Traditional exercises by year to manually input in the dataset below *
tab Ex_Year Ex_Count_Shaping_USA
tab Ex_Year Ex_Count_Shaping_China
tab Ex_Year Ex_Count_Shaping_UK
tab Ex_Year Ex_Count_Shaping_France
tab Ex_Year Ex_Count_Shaping_Germany
tab Ex_Year Ex_Count_Shaping_Russia
tab Ex_Year Ex_Count_Shaping_India

tab Ex_Year Ex_Count_Traditional_USA
tab Ex_Year Ex_Count_Traditional_China
tab Ex_Year Ex_Count_Traditional_UK
tab Ex_Year Ex_Count_Traditional_France
tab Ex_Year Ex_Count_Traditional_Germany
tab Ex_Year Ex_Count_Traditional_Russia
tab Ex_Year Ex_Count_Traditional_India

** Import Major Power-Year Dataset for OLS Regression **
import excel FPA_Military_Statecraft_OLS.xlsx, firstrow clear

* Declare data to be time-series cross-sectional (TSCS) and Create Lag Shaping Exercises*
tsset ccode1 year
generate lag_total_shaping=L.total_shaping
generate lag_total_traditional=L.total_traditional
label variable lag_total_shaping "1-Year Lag Shaping Exercsies"
label variable lag_total_traditional "1-Year Lag Traditional Exercsies"

* Generate and Label Variables *
generate postcoldwar=1 if year>1991
replace postcoldwar=0 if year<1992
label variable postcoldwar "Post-Cold War Uncertainty"
generate log_spending=log(mil_spending)
label variable log_spending "Spending (log)"
label variable total_shaping "Number of Shaping Exercises"
label variable total_traditional "Number of Traditional Exercises"

* Manually Import Doctrinal Uncertainty Adopted from Wordstat *
generate doct_uncertainty=1 if abbrev1=="USA"
replace doct_uncertainty=0 if year== 1980 | year==1981
replace doct_uncertainty=1.91 if abbrev1=="USA" & year==1982|year==1983|year==1984|year==1985
replace doct_uncertainty=.99 if abbrev1=="USA" & year== 1986|year==1987|year==1988|year==1989|year==1990|year==1991|year==1992
replace doct_uncertainty=2.12 if abbrev1=="USA" & year==1993|year==1994|year==1995|year==1996|year==1997|year==1998|year==1999|year==2000
replace doct_uncertainty=3.76 if abbrev1=="USA" & year==2001|year==2002|year==2003|year==2004|year==2005|year==2006|year==2007
replace doct_uncertainty=6.28 if abbrev1=="USA" & year==2008|year==2009|year==2010
replace doct_uncertainty=2.69 if abbrev1=="USA" & year==2011|year==2012|year==2013|year==2014|year==2015|year==2016
replace doct_uncertainty=. if abbrev1!="USA"
label variable doct_uncertainty "Doctrinal Uncertainty"

* Manually Input Average Exercise Size Adopted from Main Dataset (see above) *
generate ave_ex_size=1
replace ave_ex_size=37000 if year==1980
replace ave_ex_size=35630.77 if year==1981
replace ave_ex_size=31305.55 if year==1982
replace ave_ex_size=41137.5 if year==1983
replace ave_ex_size=41239.29 if year==1984
replace ave_ex_size= 21401.43 if year==1985
replace ave_ex_size=19995 if year==1986
replace ave_ex_size=24393.18 if year==1987
replace ave_ex_size=50009.09 if year==1988
replace ave_ex_size=54844.45 if year==1989
replace ave_ex_size=29900 if year==1990
replace ave_ex_size=22844.45 if year==1991
replace ave_ex_size=81709.09 if year==1992
replace ave_ex_size=83136 if year==1993
replace ave_ex_size=5282.083 if year==1994
replace ave_ex_size=8774.154 if year==1995
replace ave_ex_size=3512.5 if year==1996
replace ave_ex_size=7541.5 if year==1997
replace ave_ex_size=10517.65 if year==1998
replace ave_ex_size=74616.9 if year==1999
replace ave_ex_size=8078.933 if year==2000
replace ave_ex_size=9968.75 if year==2001
replace ave_ex_size=5831.8 if year==2002
replace ave_ex_size=2918.667 if year==2003
replace ave_ex_size=3671.737 if year==2004
replace ave_ex_size=5922.048 if year==2005
replace ave_ex_size=2681.177 if year==2006
replace ave_ex_size=4665.682 if year==2007
replace ave_ex_size=10286.25 if year==2008
replace ave_ex_size=7291.333 if year==2009
replace ave_ex_size=9206.667 if year==2010
replace ave_ex_size=17452.14  if year==2011
replace ave_ex_size=19211.36 if year==2012
replace ave_ex_size=17086.59 if year==2013
replace ave_ex_size=11817.78  if year==2014
replace ave_ex_size=14419.6 if year==2015
replace ave_ex_size=12026.25 if year==2016
generate log_ave_ex_size=log(ave_ex_size)
label variable log_ave_ex_size "Ave Exercise Size (log)"

** Table A.1: OLS Regression Models (DV is # of Shaping Exercises) **
quietly reg total_shaping doct_uncertainty log_spending log_ave_ex_size total_traditional if abbrev1=="USA", vce(robust)
estimates store M1
quietly reg total_shaping doct_uncertainty lag_total_shaping log_spending log_ave_ex_size total_traditional if abbrev1=="USA"
estimates store M2
quietly reg total_shaping postcoldwar log_spending log_ave_ex_size total_traditional if abbrev1=="USA", vce(robust)
estimates store M3
quietly reg total_shaping postcoldwar lag_total_shaping log_spending log_ave_ex_size total_traditional if abbrev1=="USA", vce(robust)
estimates store M4
quietly reg total_shaping postcoldwar log_spending log_ave_ex_size total_traditional if abbrev1!="USA", vce(cluster ccode1)
estimates store M5
quietly reg total_shaping postcoldwar lag_total_shaping log_spending log_ave_ex_size total_traditional if abbrev1!="USA", vce(cluster ccode1)
estimates store M6
quietly reg total_shaping postcoldwar log_spending log_ave_ex_size total_traditional if abbrev1=="RUS", vce(robust)
estimates store M7
quietly reg total_shaping postcoldwar lag_total_shaping log_spending log_ave_ex_size total_traditional if abbrev1=="RUS"
estimates store M8

estout M1 M2 M3 M4 M5 M6 M7 M8, cells(b(star fmt(3)) se(par fmt(2)))   ///
   legend label varlabels(_cons constant)               ///
   stats(r2 N bic, fmt(3 0))   

** End of file **
clear
